package com.thinkingcoder.tcmq.core.model;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.atomic.AtomicLong;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * tc message model.
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Message<T> {

    // private String topic;

    private static final AtomicLong idGen = new AtomicLong(0);
    private Long id;

    private T body;

    private Map<String, String> headers = new HashMap<>(); // 系统属性，X-version=1.0

    // private Map<String, String> properties; // 业务属性

    public static Long nextId() {
        return idGen.getAndIncrement();
    }

    public static Message<String> create(String body, Map<String, String> headers) {
        return new Message<>(nextId(), body, headers);
    }

}
